﻿/*
 *********************************************************************
 *    Management Extensions for Windows Windows Server AppFabric     *
 *********************************************************************
 *    Author    : Fatih Boy [fatih@enterprisecoding.com]             *
 *    Web site  : http://www.enterprisecoding.com                    *
 *********************************************************************
 *    License   : GNU Library General Public License (LGPL)          * 
 *********************************************************************
 */

using System.Globalization;

namespace Com.Enterprisecoding.AppFabric.Extensions.Client.ObjectPicker {
    public sealed class ADEntry {
        #region Data Members
        private string name;
        private string upn; 
        #endregion

        #region Properties
        public string Class { get; set; }
        public string Name { get { return name; } }
        public string UPN {
            get { return upn; }
            set {
                upn = value;
                SetName();
            }
        } 
        #endregion

        private void SetName(){
            var pathname = (IAdsPathname)new Pathname();
            pathname.Set(upn, 1);

            var element = pathname.GetElement(0);
            var numElements = pathname.GetNumElements();
            var str2 = string.Empty;
            switch (numElements) {
                case 1:
                    str2 = pathname.Retrieve(9);
                    break;

                case 2:
                case 3:
                    str2 = pathname.GetElement(1);
                    break;
            }
            name = string.Format(CultureInfo.InvariantCulture, @"{0}\{1}", new object[] { str2, element });
        }
    }
}